﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_CalWage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            String e_Id = "e001";
            this.SqlDataSource2.SelectParameters["e_Id"].DefaultValue = e_Id;//这个就是给参数的赋值语句
            this.SqlDataSource2.DataBind();
            this.GridView1.DataBind();
        }
    }
    protected void btnSeacrh_Click(object sender, EventArgs e)
    {
        String e_Id = "e001";
        this.SqlDataSource2.SelectParameters["e_Id"].DefaultValue = e_Id;//这个就是给参数的赋值语句
        this.SqlDataSource2.DataBind();
        this.GridView1.DataBind();

    }
    protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        GridView1.DataBind();
    }

    protected void btnMEmployee_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Employee.aspx");
    }
    protected void btnMWage_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Wage.aspx");
    }
    protected void btnMUser_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/User.aspx");
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=pms;User ID=sa;Password=xi123456,y");
        conn.Open();

        ArrayList list1 = new ArrayList();//存放工资
        ArrayList list2 = new ArrayList();//存放d_Id
        int i = 0;
        using (SqlCommand cmd = conn.CreateCommand())
        {
            cmd.CommandText = "select * from [Wage]";
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    double wage = reader.GetDouble(1);
                    list1.Add(wage);
                    // s1[i] = reader.GetDouble(1);//得到基本工资
                    String Id = reader.GetString(2);
                    list2.Add(Id);//得到基本工资对应的职务编号
                    i++;
                    // lblName.Text = i + " " + Wage;
                    lblName.Text = i + " " + wage + " " + i + list1[i - 1] + list1[0];

                }
            }
        }
        using (SqlCommand cmd = conn.CreateCommand())
        {
            for (int j = 0; j < i; j++)
            {
                String Id = list2[j].ToString();
                cmd.CommandText = "select d_Wage from [Duty] where d_Id = '" + Id + "'";
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        double d_Wage = reader.GetDouble(0);
                        list1[j] = d_Wage + (double)list1[j];//得到总工资

                    }
                }
            }

        }
        using (SqlCommand cmd = conn.CreateCommand())
        {
            for (int j = 0; j < i; j++)
            {
                String d = list2[j].ToString();
                double wage = (double)list1[j];
                cmd.CommandText = "update Wage set w_Gw = '" + wage + "' where d_Id = '" + d + "'";
                cmd.ExecuteNonQuery();
            }
        }

    }
 }